﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>部门管理</title>
    <#include "../common/link.ftl"/>

</head>
<script>
    $(function () {
        $(".btn-input").click(function () {
            //清空表单数据
            $("#editForm input").val('');
            //找到绑定这个事件的标签,获取这个标签的data前缀,json为后缀的属性的值
            var json = $(this).data('json');
            //数据回显
            if(json){
                $("#editForm input[name=id]").val(json.id);
                $("#editForm input[name=name]").val(json.name)
                $("#editForm input[name=sn]").val(json.sn);

                //标题改为编辑
                $('#myModalLabel').html("编辑操作")
            }else{
                $('#myModalLabel').html("新增操作")
            }
            //弹出模态框
            $('#myModal').modal('show');
        })

        //保存按钮进行的操作
        $("#saveOrUpdateButton").click(function () {
            //将表单转为异步请求,并且马上提交请求
            $("#editForm").ajaxSubmit(function (data) {
                $.messager.confirm("温馨提示",data.msg,function () {
                    window.location.reload();
                })
            });
        })
    });

</script>


<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl"/>
    <#--<c:set var="currentMenu" value="department"/>-->
    <!--菜单回显-->
    <#assign currentMenu = "department">
    <#include "../common/menu.ftl"/>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>部门管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/department/list.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <@shiro.hasPermission name="department:saveOrUpdate">
                        <a class="btn btn-success btn-input" style="margin: 10px">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </@shiro.hasPermission>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>部门名称</th>
                            <th>部门编号</th>
                            <th>操作</th>
                        </tr>
                            <#list pageResult.list as department>
                            <tr>
                                <td>${department_index + 1}</td>
                                <td>${department.name}</td>
                                <td>${department.sn}</td>
                                <td>
                                    <@shiro.hasPermission name="department:saveOrUpdate">
                                    <a data-json='${department.json}'
                                       class="btn btn-info btn-xs btn-input">
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    </@shiro.hasPermission>
                                    <@shiro.hasPermission name="department:delete">
                                        <a data-id="${department.id}" data-url="/department/delete.do" data-list="/department/list.do"
                                           class="btn btn-danger btn-xs btn-delete">
                                            <span class="glyphicon glyphicon-trash"></span> 删除
                                        </a>
                                    </@shiro.hasPermission>
                                </td>
                            </tr>
                            </#list>
                    </table>
                    <#include "../common/page.ftl"/>
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl"/>
</div>
<#--新增/编辑模态框-->

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/department/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden"  name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name"
                                   placeholder="请输入部门名">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">编码：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="sn" name="sn"
                                   placeholder="请输入部门编码">
                        </div>
                    </div>
            </div>
            <div class="modal-footer">
                <button id="saveOrUpdateButton" type="button" class="btn btn-primary">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>
